#include "dominion.h"
#include "dominion_helpers.h"
#include "rngs.h"
#include <stdio.h>
#include <math.h>
#include <stdlib.h>

#define NOISY_TEST 1

//most of the structure and random functions were borrowed from betterTestDrawCard

int checkscoreFor(int p, struct gameState *post, int score) {
  int r;
  int errornum = 0;

  r = scoreFor(p, post); //check against the real function
  if (r != score) { //if the real function and the test data do not match
	  errornum++; //count an error
  }
  return 0;

}



int main() {
	int i;
	int p;
	int n;
	int score = 0;

	struct gameState G;

	printf ("Testing scoreFor():\n");

	//borrowed from betterTestDrawCard
	SelectStream(2);
	PutSeed(3);

	for (n = 0; n < 2000; n++) {
	    for (i = 0; i < sizeof(struct gameState); i++) {
	      ((char*)&G)[i] = floor(Random() * 256);
	    }

	 //end of copy

	//set some random values
	p = floor(Random() * MAX_PLAYERS); //set the number of players random
	G.deckCount[p] = floor(Random() * MAX_DECK); //set the deck count to random number
	G.discardCount[p] = floor(Random() * MAX_DECK); //set the discard count to a random number
	G.handCount[p] = floor(Random() * MAX_HAND); //set the hand count to a random number

//this is straight from the dominion.c file
	//score from hand
	for (i = 0; i < G.handCount[p]; i++)
	{
	    if (G.hand[p][i] == curse) { score = score - 1; };
	    if (G.hand[p][i] == estate) { score = score + 1; };
	    if (G.hand[p][i] == duchy) { score = score + 3; };
	    if (G.hand[p][i] == province) { score = score + 6; };
	    if (G.hand[p][i] == great_hall) { score = score + 1; };
	    if (G.hand[p][i] == gardens) { score = score + ( fullDeckCount(p, 0, &G) / 10 ); };
	 }

	 //score from discard
	 for (i = 0; i < G.discardCount[p]; i++)
	 {
	    if (G.discard[p][i] == curse) { score = score - 1; };
	    if (G.discard[p][i] == estate) { score = score + 1; };
	    if (G.discard[p][i] == duchy) { score = score + 3; };
	    if (G.discard[p][i] == province) { score = score + 6; };
	    if (G.discard[p][i] == great_hall) { score = score + 1; };
	    if (G.discard[p][i] == gardens) { score = score + ( fullDeckCount(p, 0, &G) / 10 ); };
	 }

	 //score from deck
	 for (i = 0; i < G.discardCount[p]; i++)
	 {
	    if (G.deck[p][i] == curse) { score = score - 1; };
	    if (G.deck[p][i] == estate) { score = score + 1; };
	    if (G.deck[p][i] == duchy) { score = score + 3; };
	    if (G.deck[p][i] == province) { score = score + 6; };
	    if (G.deck[p][i] == great_hall) { score = score + 1; };
	    if (G.deck[p][i] == gardens) { score = score + ( fullDeckCount(p, 0, &G) / 10 ); };
	 }

	 //checkscoreFor takes player, state, and score
	 checkscoreFor(p, &G, score);
	}
	 printf ("ALL TESTS OK\n");

	exit(0);
}




